#Outlier hypothesis

scores <- seq(-5,105, length=110)
normal <- dnorm(scores, mean=50, sd=15)
value.1 <- dnorm(median(scores), mean=50, sd=15)
value.2 <- dnorm(median(scores) + .5*sd(scores), mean=50, sd=15)
value.3 <- dnorm(median(scores) + .25*sd(scores), mean=50, sd=15)
plot (normal~scores, type="l", xlab="Distribution of 20,000 Simulated Medians", ylab="", main="Outlier Hypothesis", sub="Committees Created Randomly from Entire House", axes=FALSE, frame.plot=TRUE)
segments (median(scores), -1, median(scores), value.1)
segments (median(scores) + .5*sd(scores), -1, median(scores) + .5*sd(scores), value.2)
segments (median(scores) + .25*sd(scores), -1, median(scores) + .25*sd(scores), value.3)

more.lines<- function(x.loc1){
x.loc<-matrix(0, 1000, 1)
y.loc<-matrix(0, 1000, 1)
x.loc[1,1]<- x.loc1 
y.loc[1,1]<-dnorm(x.loc[1,1],mean=50, sd=15) 
for (i in 2:1000){
x.loc[i,1] <- x.loc[i-1,1]+.10 
y.loc[i,1] <- dnorm(x.loc[i,1],mean=50, sd=15)}
for (i in 2:1000){segments (x.loc[i,1], -1, x.loc[i,1], y.loc[i,1])}
}
func.plot <- more.lines((median(scores) + .5*sd(scores)))
text(locator(2), c("Observed Floor Median", "Observed Committee Median" ), adj=0) 





#Opposing Outlier hypothesis

scores <- seq(-5,105, length=110)
normal <- dnorm(scores, mean=50, sd=15)
value.1 <- dnorm(median(scores), mean=50, sd=15)
value.2 <- dnorm(median(scores) + .5*sd(scores), mean=50, sd=15)
value.3 <- dnorm(median(scores) + .25*sd(scores), mean=50, sd=15)
plot (normal~scores, type="l", xlab="Distribution of 20,000 Simulated Medians", ylab="", main="Opposing Outlier Hypothesis", sub="Committees Created Randomly from Party Contingent in House", axes=FALSE, frame.plot=TRUE)
segments (median(scores), -1, median(scores), value.1)
segments (median(scores) + .5*sd(scores), -1, median(scores) + .5*sd(scores), value.2)
segments (median(scores) + .25*sd(scores), -1, median(scores) + .25*sd(scores), value.3)

more.lines<- function(x.loc1){
x.loc<-matrix(0, 1000, 1)
y.loc<-matrix(0, 1000, 1)
x.loc[1,1]<- x.loc1 
y.loc[1,1]<-dnorm(x.loc[1,1],mean=50, sd=15) 
for (i in 2:1000){
x.loc[i,1] <- x.loc[i-1,1]+.10 
y.loc[i,1] <- dnorm(x.loc[i,1],mean=50, sd=15)}
for (i in 2:1000){segments (x.loc[i,1], -1, x.loc[i,1], y.loc[i,1])}
}
func.plot <- more.lines((median(scores) + .5*sd(scores)))
text(locator(2), c("Observed Floor Median", "Observed Party Median" ), adj=0)


#Representative Committee Hypothesis
scores <- seq(-5,105, length=110)
normal <- dnorm(scores, mean=50, sd=15)
value.1 <- dnorm(median(scores), mean=50, sd=15)
value.3 <- dnorm(median(scores) + .25*sd(scores), mean=50, sd=15)
plot (normal~scores, type="l", xlab="Distribution of 20,000 Simulated Medians", ylab="", main="Representative Committee Hypothesis", sub="Committees Created Randomly from Entire House", axes=FALSE, frame.plot=TRUE)
segments (median(scores), -1, median(scores), value.1)
segments (median(scores) + .25*sd(scores), -1, median(scores) + .25*sd(scores), value.3)

more.lines<- function(x.loc1, x.loc2){
x.loc<-matrix(0, 1000, 1)
y.loc<-matrix(0, 1000, 1)
x.loc[1,1]<- x.loc1 
y.loc[1,1]<-dnorm(x.loc[1,1],mean=50, sd=15) 
x.loc2 <- x.loc2
for (i in 2:1000){
x.loc[i,1] <- x.loc[i-1,1]+.10 
y.loc[i,1] <- dnorm(x.loc[i,1],mean=50, sd=15)
if (x.loc2 > x.loc[i,1]){
segments (x.loc[i,1], -1, x.loc[i,1], y.loc[i,1])}}
}
func.plot <- more.lines(median(scores), (median(scores) + .25*sd(scores)))
text(locator(1), c("Observed Committee Median"),adj=0)




#Representative Majority Members Hypothesis
scores <- seq(-5,105, length=110)
normal <- dnorm(scores, mean=50, sd=15)
value.1 <- dnorm(median(scores), mean=50, sd=15)
value.2 <- dnorm(median(scores) + .5*sd(scores), mean=50, sd=15)
plot (normal~scores, type="l", xlab="Distribution of 20,000 Simulated Medians", ylab="", main="Representative Majority Members Hypothesis", sub="Committees Created Randomly from Majority Party Contingent in House", axes=FALSE, frame.plot=TRUE)
segments (median(scores), -1, median(scores), value.1)
segments (median(scores) + .5*sd(scores), -1, median(scores) + .5*sd(scores), value.2)


more.lines<- function(x.loc1, x.loc2){
x.loc<-matrix(0, 1000, 1)
y.loc<-matrix(0, 1000, 1)
x.loc[1,1]<- x.loc1 
y.loc[1,1]<-dnorm(x.loc[1,1],mean=50, sd=15) 
x.loc2 <- x.loc2
for (i in 2:1000){
x.loc[i,1] <- x.loc[i-1,1]+.10 
y.loc[i,1] <- dnorm(x.loc[i,1],mean=50, sd=15)
if (x.loc2 > x.loc[i,1]){
segments (x.loc[i,1], -1, x.loc[i,1], y.loc[i,1])}}
}
func.plot <- more.lines(median(scores), (median(scores) + .5*sd(scores)))
text(locator(1), c("Party Comm. Median"),adj=0)
